<?

/**
* local collection functions of tocmenu_31
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLHandlers
*
*/

/**
* @package CLHandlers
*
*/
class CLHandlers{

  /**
   * insert into Mutation DP
   *
   * @param Database  $Db
   * @param string    $whose
   * @param string    $values
   * @param string    $srcDb
   */
  function insToMutDp(&$Db,
                       $whose,
                       $values,
                       $srcDb){

    $query  = "INSERT INTO ".$srcDb."
               (PERIODE,
                ".$whose.",
                REFERENCE,
                SOURCE,
                DATE_SOURCE,
                TR_DATE,
                DUE_DATE,
                TX_TYPE,
                AMOUNT,
                NO)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into Mutation Invoice
   *
   * @param Database  $Db
   * @param string    $whose
   * @param string    $values
   * @param string    $srcDb
   */
  function insToMutInvoice(&$Db,
                            $whose,
                           &$values,
                            $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (PERIODE,
                ".$whose.",
                REFERENCE,
                SOURCE,
                DATE_SOURCE,
                TR_DATE,
                DUE_DATE,
                TX_TYPE,
                AMOUNT,
                NO)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into Cash Bank detail mutation
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToMutCbDtl(&$Db,
                         &$values,
                          $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (REFERENCE,
                C_B_CODE,
                NO,
                PERIODE,
                TR_DATE,
                SUPPLIER_CUSTOMER,
                TX_TYPE,
                CURRENCY,
                RATE,
                AMOUNT,
                NET)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * tansfer supplier cancel DP real to Tmp table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transCclDpRealToTmpSupplier($Db,
                                       $jobId,
                                       $tmpJid,
                                       $SourceDb){

    /**
     * transfer...
     */
    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpDtlCclDpSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbDtlCclDpSupplier")."
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpSubCclDpSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbSubCclDpSupplier")."
               WHERE JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    /**
     * we reset tmp jobId
     * jobId --> tmpJid
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpDtlCclDpSupplier")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpSubCclDpSupplier")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);
  }

  /**
   * tansfer supplier invoice real to Tmp table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transIvcRealToTmpSupplier($Db,
                                     $jobId,
                                     $tmpJid,
                                     $SourceDb){

    /**
     * transfer...
     */
    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpDtlIvcSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbDtlIvcSupplier")."
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpSubIvcSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbSubIvcSupplier")."
               WHERE JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    /**
     * we reset tmp jobId
     * jobId --> tmpJid
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpDtlIvcSupplier")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpSubIvcSupplier")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);
  }

  /**
   * tansfer Supplier Cancel Dp tmp to real table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transCclDpTmpToRealSupplier($Db,
                                       $jobId,
                                       $tmpJid,
                                       $SourceDb){

    /**
     * transfer...
     */
    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbDtlCclDpSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpDtlCclDpSupplier")."
               WHERE JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbSubCclDpSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpSubCclDpSupplier")."
               WHERE JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    /**
     * we set the Jobid
     * tmpJid --> jobId
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbDtlCclDpSupplier")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbSubCclDpSupplier")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);
  }

  /**
   * tansfer supplier invoice tmp to real table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transIvcTmpToRealSupplier($Db,
                                     $jobId,
                                     $tmpJid,
                                     $SourceDb){

    /**
     * transfer...
     */
    $query	= "INSERT INTO ".$SourceDb->fetchValue("srcDbDtlIvcSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpDtlIvcSupplier")."
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query	= "INSERT INTO ".$SourceDb->fetchValue("srcDbSubIvcSupplier")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpSubIvcSupplier")."
               WHERE JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    /**
     * we set the Jobid
     * tmpJid --> jobId
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbDtlIvcSupplier")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbSubIvcSupplier")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);
  }

  /**
   * into Cash bank header
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToCbHdr($Db,
                      $values,
                      $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                REFERENCE,
                TR_DATE,
                NO,
                STATUS,
                C_B_CODE,
                IN_OUT,
                TYPE,
                CURRENCY,
                RATE,
                SUPPLIER_CUSTOMER,
                MEMO)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * into Cash bank detail
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToCbDtl($Db,
                      $values,
                      $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                TOT_AMOUNT,
                TOT_NET)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * into Cash bank sub detail
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToCbSubDtl($Db,
                         $values,
                         $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                GL_ACC,
                GL_SUB_ACC,
                DESCRIPTION,
                AMOUNT,
                NET)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into tmp detail of supplier invoice
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToTmpDtl($Db,
                        $values,
                        $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                TOT_INVOICE,
                PAYMENT,
                GAIN_LOSS,
                DISCOUNT)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into tmp sub detail of supplier DP
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToTmpSubDp($Db,
                         $values,
                         $srcDb){

    $query  = "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                PERIODE,
                REFERENCE,
                SOURCE,
                TR_DATE,
                DUE_DATE,
                SUPPLIER_CUSTOMER,
                CURRENCY,
                RATE,
                REMAIN,
                AMOUNT,
                TX_TYPE)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into tmp sub detail of supplier invoice
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToTmpSub($Db,
                       $values,
                       $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                PERIODE,
                REFERENCE,
                TR_DATE,
                DUE_DATE,
                SUPPLIER_CUSTOMER,
                CURRENCY,
                RATE,
                REMAIN,
                AMOUNT,
                TX_TYPE)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }
}

?>